'use strict';

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

//@charset "utf-8"
var hqQuote = {
	request: function () {
		var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(callback, mStock, period, dStock) {
			var dataType, thsQuote, reqObj;
			return _regenerator2.default.wrap(function _callee2$(_context2) {
				while (1) {
					switch (_context2.prev = _context2.next) {
						case 0:
							//ZHANGSHU
							dataType = ['ZQMC', 'NEW', 'ZHANGDIEFU', '3934664', 'HUANSHOU', 'HIGH', 'LOW', 'PRE'];
							_context2.prev = 1;
							thsQuote = new ThsQuote();
							_context2.next = 9;
							break;

						case 5:
							_context2.prev = 5;
							_context2.t0 = _context2['catch'](1);

							alert('需要客户端环境');
							return _context2.abrupt('return', false);

						case 9:

							dataType = dataType.join(',');
							reqObj = {
								code: mStock,
								type: dataType,
								period: period,
								onready: function () {
									var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
										var result, type, ret, data, i;
										return _regenerator2.default.wrap(function _callee$(_context) {
											while (1) {
												switch (_context.prev = _context.next) {
													case 0:
														result = {};

														dataType = dataType.split(',');
														_context.t0 = _regenerator2.default.keys(dataType);

													case 3:
														if ((_context.t1 = _context.t0()).done) {
															_context.next = 34;
															break;
														}

														type = _context.t1.value;

														if (!isNaN(type)) {
															_context.next = 7;
															break;
														}

														return _context.abrupt('continue', 3);

													case 7:
														ret = null;

														if (dataType[type] == '3934664') {
															ret = {
																code: mStock,
																type: dataType[type],
																mode: 'beforecalclastfromsvrnow1st'
															};
														} else {
															ret = { code: mStock, type: dataType[type] };
														}

														_context.prev = 9;
														_context.next = 12;
														return thsQuote.getData(ret);

													case 12:
														data = _context.sent;

														data = eval(data);
														_context.t2 = _regenerator2.default.keys(data);

													case 15:
														if ((_context.t3 = _context.t2()).done) {
															_context.next = 27;
															break;
														}

														i = _context.t3.value;

														if (undefined == result[i]) {
															result[i] = {};
														}

														if (!('zqmc' == ret.type || 'ZQMC' == ret.type)) {
															_context.next = 21;
															break;
														}

														result[i][ret.type] = data[i][ret.type];
														return _context.abrupt('continue', 15);

													case 21:
														if (!isNaN(data[i][ret.type])) {
															_context.next = 24;
															break;
														}

														result[i][ret.type] = '--';
														return _context.abrupt('continue', 15);

													case 24:
														result[i][ret.type] = data[i][ret.type];
														_context.next = 15;
														break;

													case 27:
														_context.next = 32;
														break;

													case 29:
														_context.prev = 29;
														_context.t4 = _context['catch'](9);
														return _context.abrupt('continue', 3);

													case 32:
														_context.next = 3;
														break;

													case 34:

														callback(result[dStock], dStock, mStock);

													case 35:
													case 'end':
														return _context.stop();
												}
											}
										}, _callee, this, [[9, 29]]);
									}));

									function onready() {
										return _ref2.apply(this, arguments);
									}

									return onready;
								}()
							};
							_context2.next = 13;
							return thsQuote.request(reqObj);

						case 13:
						case 'end':
							return _context2.stop();
					}
				}
			}, _callee2, this, [[1, 5]]);
		}));

		function request(_x, _x2, _x3, _x4) {
			return _ref.apply(this, arguments);
		}

		return request;
	}()
};